package com.antler.smt.portal.controller;

import com.antler.smt.entity.OrderEntity;
import com.antler.smt.enums.ResultCodeEnum;
import com.antler.smt.portal.annotation.OperateCut;
import com.antler.smt.portal.mapper.OrderInfoMapper;
import com.antler.smt.portal.mapper.RequirementInfoMapper;
import com.antler.smt.request.portal.OrderClassReq;
import com.antler.smt.response.base.Result;
import com.antler.smt.response.portal.GetRequirementListResp;
import com.antler.smt.response.portal.OrderClassifyInfoList;
import com.antler.smt.service.portal.MatchUserService;
import com.antler.smt.utils.LogUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.*;

/**
 *
 * 服务商登陆后，显示查看的订单，也可以接单
 *
 * @author zhangyi
 * @date 2018/5/16 13:08
 */
@RestController
@RequestMapping("/supplierShowOrder")
@Api(description = "服务商显示订单")
public class SupplierShowOrderController {
    /**
     * 日志
     */
    private static Logger log = LogUtil.get();

    @Resource
    private OrderInfoMapper orderInfoMapper;

    @Resource
    private RequirementInfoMapper requirementInfoMapper;

    @Resource
    private MatchUserService matchUserService;

    /**
     * 分类获取所有状态的订单信息列表
     *
     * @return
     */
    @GetMapping("/getAllRoughOrderList")
    @ApiOperation(value = "分类获取所有状态的订单信息列表(状态用,分隔)", httpMethod = "GET")
    public Result getAllRoughOrderList(OrderClassReq request){
        Result result = null;
            List list = new ArrayList();
            String[] split = request.getStatus().split(",");
            for (String s : split){
                list.add(Integer.parseInt(s));
            }
            PageHelper.startPage(request.getPageCurrent(), request.getPageSize());
            Page<OrderClassifyInfoList> listOrderInfo = orderInfoMapper.getClassifyOrderList(list);
            if (listOrderInfo != null) {
                PageInfo<OrderEntity> listPageInfo = new PageInfo(listOrderInfo);
                result = new Result(listPageInfo);
            } else {
                result = new Result(ResultCodeEnum.QUERY_DATA_ERROR, "查询未完成订单数据为空！");
            }
        return result;
    }

    /**
     * 获取此订单下的发布需求详细信息
     *
     * @return
     */
    @GetMapping("/getRequirementInfo")
    @ApiOperation(value = "获取此订单下的发布需求详细信息", httpMethod = "GET")
    @OperateCut(operationContent = "获取发布需求")
    public Result getRequirementInfo(@RequestParam(value = "orderId")Long orderId){
        Result result = null;
            GetRequirementListResp requirementByOrderId = requirementInfoMapper.getRequirementByOrderId(orderId);
            result = requirementByOrderId != null?new Result(requirementByOrderId):new Result(ResultCodeEnum.APPEND_DATA_ERROR,"查询失败！");
        return result;
    }

    /**
     * 我要接单，返回的是项目专员信息
     *
     * @return
     */
    @GetMapping("/getUserInfo")
    @ApiOperation(value = "我要接单，返回的是项目专员信息", httpMethod = "GET")
    @OperateCut(operationContent = "服务商接单")
    public Result getUserInfo(){
        Result result = null;
            result = matchUserService.getUserInfo();
        return result;
    }
}
